/**
 * 
 */
package ase.eleitweg.server.db;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.sql.DataSource;

import org.apache.log4j.Logger;
import org.springframework.jdbc.core.SqlParameter;
import org.springframework.jdbc.object.MappingSqlQuery;
import org.springframework.jdbc.object.SqlUpdate;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.TransactionCallback;
import org.springframework.transaction.support.TransactionTemplate;

import ase.eleitweg.common.Conditions;
import ase.eleitweg.common.Document;
import ase.eleitweg.common.Edge;
import ase.eleitweg.common.Group;
import ase.eleitweg.common.Node;
import ase.eleitweg.common.Run;
import ase.eleitweg.common.User;
import ase.eleitweg.common.Workflow;


/**
 * @author Aigner
 */
public class JdbcObjecteleitwegDAO implements ELeitwegDAO {
	
	private static Logger log = Logger.getLogger(JdbcObjecteleitwegDAO.class);
	
	private DataSource dataSource = null;
	private PlatformTransactionManager transactionManager = null;
	
	//SQL String
	private String sql_getInsertID = "";
	
	private String sql_getAllUsers = "";
	private String sql_getUserperNr = "";
	private String sql_insertUser = "";
	private String sql_updateUser = "";
	private String sql_deleteUser = "";
	
	private String sql_getAllGroups = "";
	private String sql_getGruppeperNr = "";
	private String sql_insertGruppe = "";
	private String sql_updateGruppe = "";
	private String sql_deleteGruppe = "";
	
	private String sql_getUsergroup = "";
	private String sql_getGroupsofUser = "";
	private String sql_insertUsergroup = "";
	private String sql_deleteUsergroup = "";
	
	private String sql_getAllWorkflows = "";
	private String sql_getWorkflow = "";
	private String sql_insertWorkflow = "";
	private String sql_updateWorkflow = "";
	private String sql_deleteWorkflow = "";
	
	private String sql_getAllActivities = "";
	private String sql_getActivity = "";
	private String sql_insertActivity = "";
	private String sql_updateActivity = "";
	private String sql_deleteActivity = "";
	
	private String sql_getAntwort = "";
	private String sql_getAntwortenfromActivity = "";
	private String sql_insertAntwort = "";
	private String sql_updateAntwort = "";
	private String sql_deleteAntwort = "";
	
	private String sql_getDokument = "";
	private String sql_getDokumentOhne = "";
	private String sql_insertDokument = "";
	private String sql_updateDokument = "";
	private String sql_deleteDokument = "";
	private String sql_deleteDokumente = "";

	private String sql_getInstanz = "";
	private String sql_getInstanzById = "";
	private String sql_getInstanzen = "";
	private String sql_getInstanzFromWorkflow = "";
	private String sql_getInstanzFromUser = "";
	private String sql_getInstanzFromActivity = "";
	private String sql_insertInstanz = "";
	private String sql_deleteInstanz = "";
	private String sql_updateInstanz = "";

	//Query Objects
	private Query_BaseUser query_getBaseUser;
	private Query_BaseGroup query_getBaseGroup;
	private Query_GetAllUsers query_getallusers;
	private Query_getInsertID query_getInsertID;
	
	private Query_GetUserperNr query_getuserpernr;
	private Query_InsertUser query_insertuser;
	private Query_updateUser query_updateuser;
	private Query_DeleteUser query_deleteuser;
	
	private Query_GetAllGroups query_getallgroups;
	private Query_GetGruppeperNr query_getgruppepernr;
	private Query_InsertGruppe query_insertgruppe;
	private Query_UpdateGruppe query_updategruppe;
	private Query_DeleteGruppe query_deletegruppe;
	
	private Query_GetUsergroup query_getusergroup;
	private Query_GetGroupsofUser query_getgroupofuser;
	private Query_InsertUsergroup query_insertusergroup;
	private Query_DeleteUsergroup query_deleteusergroup;
	
	private Query_InsertWorkflow query_insertworkflow;
	private Query_GetAllWorkflows query_getallworkflows;	
	private Query_GetWorkflow query_getworkflow;
	private Query_DeleteWorkflow query_deleteworkflow;
	private Query_UpdateWorkflow query_updateworkflow;	
	
	private Query_GetActivity query_getactivity;
	private Query_GetAllActivities query_getallactivities;
	private Query_DeleteActivity query_deleteactivity;
	private Query_UpdateActivity query_updateactivity;
	private Query_InsertActivity query_insertactivity;
	
	private Query_InsertAntwort query_insertantwort;
	private Query_DeleteAntwort query_deleteantwort;
	private Query_GetAntwort query_getantwort;	
	private Query_GetAntwortenfromActivity query_getantwortenfromactivity; 	
	private Query_UpdateAntwort query_updateantwort;
	
	private Query_GetDokument query_getdokument;
	private Query_GetDokumentOhne query_getdokumentohne;
	private Query_InsertDokument query_insertdokument;
	private Query_DeleteDokument query_deletedokument;
	private Query_DeleteDokumente query_deletedokumente;
	private Query_UpdateDokument query_updatedokument;
	
	private Query_InsertInstanz query_insertinstanz;
	private Query_GetInstanzById query_getinstanzbyid;
	private Query_GetInstanzen query_getinstanzen;
	private Query_GetInstanzFromWorkflow query_getinstanzfromworkflow;	
	private Query_GetInstanzFromUser query_getinstanzfromuser;
	private Query_GetInstanzFromActivity query_getinstanzfromactivity;
	private Query_DeleteInstanz query_deleteinstanz;
	private Query_UpdateInstanz query_updateinstanz;
	
	private class Query_BaseUser extends MappingSqlQuery {
		public Query_BaseUser(DataSource ds, String sql) {
			super(ds,sql);
		}

		protected User mapRow(ResultSet rs, int rowNumber) throws SQLException{
			User u = new User(rs.getInt("UNr"), rs.getInt("Type"), rs.getInt("Durchwahl"), rs.getString("Username"), rs.getString("Vorname"),
					          rs.getString("Nachname"), rs.getString("Email"), rs.getString("Password"));
			return u;
		}
	}
	
	private class Query_BaseGroup extends MappingSqlQuery {
		public Query_BaseGroup(DataSource ds, String sql) {
			super(ds,sql);
		}

		protected Group mapRow(ResultSet rs, int rowNumber) throws SQLException{
			Group g = new Group(rs.getInt("GNr"), rs.getString("Name"), rs.getString("Descr"));
			g.setUsers(query_getusergroup.execute(rs.getInt("GNr")));
			return g;
		}
	}
	
	private class Query_BaseWorkflow extends MappingSqlQuery {
		public Query_BaseWorkflow(DataSource ds, String sql) {
			super(ds,sql);
		}

		protected Workflow mapRow(ResultSet rs, int rowNumber) throws SQLException{
			Workflow w = new Workflow(rs.getInt("WNr"), rs.getString("Name"),
					                  rs.getDate("Datum"), rs.getString("Beschreibung"));
			
			final Object[] param = new Object[] {  rs.getInt("ANrStart") };
			log.debug("getting workflow-startnode for wf: " + rs.getInt("WNr"));
			log.debug("getting workflow-startnode: " + rs.getInt("ANrStart"));
			Node n = (Node)query_getactivity.execute(param).get(0);
			w.setStartnode(n);
			//System.out.println("!!!! startnode:" + w.getStartnode().getId());
			return w;
		}
	}
	
	private class Query_BaseActivity extends MappingSqlQuery {
		public Query_BaseActivity(DataSource ds, String sql) {
			super(ds,sql);
		}

		protected Node mapRow(ResultSet rs, int rowNumber) throws SQLException{
			//Workflow w = (Workflow)query_getworkflow.execute(rs.getInt("WNr")).get(0);
			Group g = (Group)query_getgruppepernr.execute(rs.getInt("GNr")).get(0);
			
			Node n = new Node(rs.getInt("ANr"), g, rs.getString("Name"), 
					          rs.getString("Frage"),null, null, rs.getInt("x"), rs.getInt("y"));
			return n;
		}
	}
	
	private class Query_BaseAnswer extends MappingSqlQuery {
		public Query_BaseAnswer(DataSource ds, String sql) {
			super(ds,sql);
		}

		protected Edge mapRow(ResultSet rs, int rowNumber) throws SQLException{
			Node curr = (Node)query_getactivity.execute(rs.getInt("ANrCurr")).get(0);
			Node next = (Node)query_getactivity.execute(rs.getInt("ANrNext")).get(0);
			
			Edge e = new Edge(rs.getString("Text"), curr, next, rs.getInt("ANr"));
			return e;
		}
	}
	
	private class Query_BaseInstance extends MappingSqlQuery {
		public Query_BaseInstance(DataSource ds, String sql) {
			super(ds,sql);
		}

		protected Run mapRow(ResultSet rs, int rowNumber) throws SQLException{
			//Workflow w = (Workflow)query_getworkflow.execute(rs.getInt("WNr")).get(0);
			Workflow w = getWorkflow(rs.getInt("WNr"));
			User u = (User)query_getuserpernr.execute(rs.getInt("UNr")).get(0);
			//Node n = (Node)query_getactivity.execute(rs.getInt("ANr")).get(0);
			Node n = null;
			for(Node nx : w.getNodes()) {
				if(nx.getId() == rs.getInt("ANr")) {
					n = nx;
				}
			}
			
			Run r = new Run(w,u,n,rs.getDate("Datum"),rs.getBoolean("Accepted"), rs.getInt("INr"), 
					        rs.getString("Description"), rs.getString("Name"));
			return r;
		}
	}
	
	private class Query_GetAllUsers extends Query_BaseUser {
		 public Query_GetAllUsers(DataSource ds) {
			 super(ds, sql_getAllUsers);
			 compile();
		 }
	}
	
	private class Query_GetUserperNr extends Query_BaseUser {
		 public Query_GetUserperNr(DataSource ds) {
			 super(ds, sql_getUserperNr);
			 super.declareParameter(new SqlParameter("UNr", Types.INTEGER));
			 compile();
		 }
	}
	
	private class Query_InsertUser extends SqlUpdate{
		public Query_InsertUser(DataSource ds){
			setDataSource(ds);
			setSql(sql_insertUser);
			declareParameter(new SqlParameter(Types.VARCHAR)); //Username
			declareParameter(new SqlParameter(Types.VARCHAR)); //Vorname
			declareParameter(new SqlParameter(Types.VARCHAR)); //Nachname
			declareParameter(new SqlParameter(Types.INTEGER)); //Durchwahl
			declareParameter(new SqlParameter(Types.VARCHAR)); //Email
			declareParameter(new SqlParameter(Types.VARCHAR)); //Password
			declareParameter(new SqlParameter(Types.INTEGER)); //Type
		}
	}
	
	private class Query_DeleteUser extends SqlUpdate{
		public Query_DeleteUser(DataSource ds){
			setDataSource(ds);
			setSql(sql_deleteUser);
			declareParameter(new SqlParameter("UNr", Types.INTEGER));
		}
	}
	
	private class Query_updateUser extends SqlUpdate{
		public Query_updateUser(DataSource ds){
			setDataSource(ds);
			setSql(sql_updateUser);
			declareParameter(new SqlParameter("Username",  Types.VARCHAR)); //Username
			declareParameter(new SqlParameter("Vorname",   Types.VARCHAR)); //Vorname
			declareParameter(new SqlParameter("Nachname",  Types.VARCHAR)); //Nachname
			declareParameter(new SqlParameter("Durchwahl", Types.INTEGER)); //Durchwahl
			declareParameter(new SqlParameter("Email",     Types.VARCHAR)); //Email
			declareParameter(new SqlParameter("Password",  Types.VARCHAR)); //Password
			declareParameter(new SqlParameter("Type",      Types.INTEGER)); //Type
			declareParameter(new SqlParameter("UNr",       Types.INTEGER)); //ID to search
		}
	}
	
	private class Query_GetAllGroups extends Query_BaseGroup {
		public Query_GetAllGroups(DataSource ds) {
			super(ds, sql_getAllGroups);
			compile();
		}
	}
	
	private class Query_GetGruppeperNr extends Query_BaseGroup {
		public Query_GetGruppeperNr(DataSource ds) {
			super(ds, sql_getGruppeperNr);
			super.declareParameter(new SqlParameter("GNr", Types.INTEGER));
			compile();
		}
	}
	
	private class Query_InsertGruppe extends SqlUpdate {
		public Query_InsertGruppe(DataSource ds) {
			setDataSource(ds);
			setSql(sql_insertGruppe);
			declareParameter(new SqlParameter(Types.VARCHAR)); //Name
			declareParameter(new SqlParameter(Types.VARCHAR)); //Descr			
		}
	}
	
	private class Query_DeleteGruppe extends SqlUpdate{
		public Query_DeleteGruppe(DataSource ds){
			setDataSource(ds);
			setSql(sql_deleteGruppe);
			declareParameter(new SqlParameter("GNr", Types.INTEGER));
		}
	}
	
	private class Query_UpdateGruppe extends SqlUpdate {
		public Query_UpdateGruppe(DataSource ds) {
			setDataSource(ds);
			setSql(sql_updateGruppe);
			declareParameter(new SqlParameter("Name", Types.VARCHAR)); //Name
			declareParameter(new SqlParameter(Types.VARCHAR)); //Descr
			declareParameter(new SqlParameter("GNr", Types.INTEGER)); //ID to search
		}
	}
	
	private class Query_GetUsergroup extends Query_BaseUser {
		public Query_GetUsergroup(DataSource ds) {
			super(ds, sql_getUsergroup);
			super.declareParameter(new SqlParameter("GNr", Types.INTEGER));
			compile();
		}
	}
	
	private class Query_GetGroupsofUser extends Query_BaseGroup {
		public Query_GetGroupsofUser(DataSource ds) {
			super(ds, sql_getGroupsofUser);
			super.declareParameter(new SqlParameter("UNr", Types.INTEGER));
			compile();
		}
	}
	
	private class Query_InsertUsergroup extends SqlUpdate {
		public Query_InsertUsergroup(DataSource ds) {
			setDataSource(ds);
			setSql(sql_insertUsergroup);
			declareParameter(new SqlParameter(Types.INTEGER)); //UNr
			declareParameter(new SqlParameter(Types.INTEGER)); //GNr
		}
	}
	
	private class Query_DeleteUsergroup extends SqlUpdate {
		public Query_DeleteUsergroup(DataSource ds) {
			setDataSource(ds);
			setSql(sql_deleteUsergroup);
			declareParameter(new SqlParameter(Types.INTEGER)); //UNr
			declareParameter(new SqlParameter(Types.INTEGER)); //GNr
		}
	}
	
	private class Query_GetAllWorkflows extends Query_BaseWorkflow {
		public Query_GetAllWorkflows(DataSource ds) {
			super(ds, sql_getAllWorkflows);
			compile();
		}
	}
	
	private class Query_GetWorkflow extends Query_BaseWorkflow {
		public Query_GetWorkflow(DataSource ds) {
			super(ds, sql_getWorkflow);
			super.declareParameter(new SqlParameter("WNr", Types.INTEGER));
			compile();
		}
	}

	private class Query_InsertWorkflow extends SqlUpdate {
		public Query_InsertWorkflow(DataSource ds) {
			setDataSource(ds);
			setSql(sql_insertWorkflow);
			declareParameter(new SqlParameter(Types.VARCHAR)); //Name
			declareParameter(new SqlParameter(Types.DATE));    //Datum
			declareParameter(new SqlParameter(Types.VARCHAR)); //Beschreibung
			declareParameter(new SqlParameter(Types.INTEGER)); //ANrStart
		}
	}
	
	private class Query_DeleteWorkflow extends SqlUpdate {
		public Query_DeleteWorkflow(DataSource ds) {
			setDataSource(ds);
			setSql(sql_deleteWorkflow);
			declareParameter(new SqlParameter(Types.INTEGER)); //WNr
		}
	}
	
	private class Query_UpdateWorkflow extends SqlUpdate {
		public Query_UpdateWorkflow(DataSource ds) {
			setDataSource(ds);
			setSql(sql_updateWorkflow);
			declareParameter(new SqlParameter(Types.VARCHAR)); //Name
			declareParameter(new SqlParameter(Types.DATE));    //Datum
			declareParameter(new SqlParameter(Types.VARCHAR)); //Beschreibung
			declareParameter(new SqlParameter(Types.INTEGER)); //ANrStart
			declareParameter(new SqlParameter(Types.INTEGER)); //WNr
			
		}
	}	

	private class Query_GetActivity extends Query_BaseActivity {
		public Query_GetActivity(DataSource ds) {
			super(ds, sql_getActivity);
			//super.declareParameter(new SqlParameter("WNr", Types.INTEGER));
			super.declareParameter(new SqlParameter("ANr", Types.INTEGER));
			compile();
		}
	}
	
	private class Query_GetAllActivities extends Query_BaseActivity {
		public Query_GetAllActivities(DataSource ds) {
			super(ds, sql_getAllActivities);
			super.declareParameter(new SqlParameter("WNr", Types.INTEGER));
			compile();
		}
	}
	
	private class Query_InsertActivity extends SqlUpdate {
		public Query_InsertActivity(DataSource ds) {
			setDataSource(ds);
			setSql(sql_insertActivity);
			declareParameter(new SqlParameter(Types.INTEGER)); //WNr
			declareParameter(new SqlParameter(Types.INTEGER)); //GNr
			declareParameter(new SqlParameter(Types.VARCHAR)); //Name
			declareParameter(new SqlParameter(Types.VARCHAR)); //Frage
			declareParameter(new SqlParameter(Types.INTEGER)); //x
			declareParameter(new SqlParameter(Types.INTEGER)); //y
			
		}
	}
	
	private class Query_DeleteActivity extends SqlUpdate {
		public Query_DeleteActivity(DataSource ds) {
			setDataSource(ds);
			setSql(sql_deleteActivity);
			declareParameter(new SqlParameter(Types.INTEGER)); //WNr
			declareParameter(new SqlParameter(Types.INTEGER)); //ANr
		}
	}
	
	private class Query_UpdateActivity extends SqlUpdate {
		public Query_UpdateActivity(DataSource ds) {
			setDataSource(ds);
			setSql(sql_updateActivity);
			declareParameter(new SqlParameter(Types.INTEGER)); //GNr
			declareParameter(new SqlParameter(Types.VARCHAR)); //Name
			declareParameter(new SqlParameter(Types.VARCHAR)); //Frage
			declareParameter(new SqlParameter(Types.INTEGER)); //x
			declareParameter(new SqlParameter(Types.INTEGER)); //y
			
			declareParameter(new SqlParameter(Types.INTEGER)); //WNr
			declareParameter(new SqlParameter(Types.INTEGER)); //ANr
		}		
	}
	
	private class Query_GetAntwort extends Query_BaseAnswer {
		public Query_GetAntwort(DataSource ds) {
			super(ds, sql_getAntwort);
			super.declareParameter(new SqlParameter("ANr", Types.INTEGER));
			compile();
		}
	}
	
	private class Query_GetAntwortenfromActivity extends Query_BaseAnswer {
		public Query_GetAntwortenfromActivity(DataSource ds) {
			super(ds, sql_getAntwortenfromActivity);
			super.declareParameter(new SqlParameter("ANrCurr", Types.INTEGER));
			compile();
		}
	}
	
	private class Query_InsertAntwort extends SqlUpdate {
		public Query_InsertAntwort(DataSource ds) {
			setDataSource(ds);
			setSql(sql_insertAntwort);
			declareParameter(new SqlParameter(Types.INTEGER)); //ANrCurr
			declareParameter(new SqlParameter(Types.INTEGER)); //ANrNext
			declareParameter(new SqlParameter(Types.VARCHAR)); //Text
		}
	}
	
	private class Query_DeleteAntwort extends SqlUpdate {
		public Query_DeleteAntwort(DataSource ds) {
			setDataSource(ds);
			setSql(sql_deleteAntwort);
			declareParameter(new SqlParameter("ANr", Types.INTEGER)); //ANr
		}
	}
	
	private class Query_UpdateAntwort extends SqlUpdate {
		public Query_UpdateAntwort(DataSource ds) {
			setDataSource(ds);
			setSql(sql_updateAntwort);
			declareParameter(new SqlParameter("ANrCurr", Types.INTEGER)); //ANrCurr
			declareParameter(new SqlParameter("ANrNext", Types.INTEGER)); //ANrNext
			declareParameter(new SqlParameter("Text",    Types.VARCHAR)); //Text
			declareParameter(new SqlParameter("ANr",     Types.INTEGER)); //ANr
		}
	}

	private class Query_GetDokument extends MappingSqlQuery {
		public Query_GetDokument(DataSource ds) {
			super(ds, sql_getDokument);
			super.declareParameter(new SqlParameter("INr", Types.INTEGER));
			compile();
		}
		
		protected Document mapRow(ResultSet rs, int rowNumber) throws SQLException {
			Document d = new Document(rs.getInt("DNr"),rs.getString("Name"),
					                  rs.getInt("Version"), rs.getBytes("Binary"), null);
			for(Run r : getInstances()) {
				if(r.getId() == rs.getInt("INR")) {
					d.setR(r);
				}
			}
			return d;
		}
	}
	
	private class Query_GetDokumentOhne extends MappingSqlQuery {
		public Query_GetDokumentOhne(DataSource ds) {
			super(ds, sql_getDokumentOhne);
			super.declareParameter(new SqlParameter("INr", Types.INTEGER));
			compile();
		}
		
		protected Document mapRow(ResultSet rs, int rowNumber) throws SQLException {
			Document d = new Document(rs.getInt("DNr"),rs.getString("Name"),
	                  				  rs.getInt("Version"), (new String("")).getBytes(), null);
			for(Run r : getInstances()) {
				if(r.getId() == rs.getInt("INR")) {
					d.setR(r);
				}
			}
			return d;
		}
	}
	
	private class Query_InsertDokument extends SqlUpdate {
		public Query_InsertDokument(DataSource ds) {
			setDataSource(ds);
			setSql(sql_insertDokument);
			declareParameter(new SqlParameter(Types.VARCHAR)); //Name
			declareParameter(new SqlParameter(Types.INTEGER)); //Version
			declareParameter(new SqlParameter(Types.BINARY)); //Binary
			declareParameter(new SqlParameter(Types.INTEGER)); //RunId
		}
	}
	
	private class Query_DeleteDokument extends SqlUpdate {
		public Query_DeleteDokument(DataSource ds) {
			setDataSource(ds);
			setSql(sql_deleteDokument);
			declareParameter(new SqlParameter(Types.INTEGER)); //DNr
		}
	}
	
	private class Query_DeleteDokumente extends SqlUpdate {
		public Query_DeleteDokumente(DataSource ds) {
			setDataSource(ds);
			setSql(sql_deleteDokumente);
			declareParameter(new SqlParameter(Types.INTEGER)); //INr
		}
	}
	
	private class Query_UpdateDokument extends SqlUpdate {
		public Query_UpdateDokument(DataSource ds) {
			setDataSource(ds);
			setSql(sql_updateDokument);
			declareParameter(new SqlParameter(Types.VARCHAR)); //Name
			declareParameter(new SqlParameter(Types.INTEGER)); //Version
			declareParameter(new SqlParameter(Types.VARCHAR)); //Binary
			declareParameter(new SqlParameter(Types.INTEGER)); //DNr
		}
	}
	
	private class Query_GetInstanzFromWorkflow extends Query_BaseInstance {
		public Query_GetInstanzFromWorkflow(DataSource ds) {
			super(ds, sql_getInstanzFromWorkflow);
			super.declareParameter(new SqlParameter("WNr", Types.INTEGER));
			compile();
		}
	}
	
	private class Query_GetInstanzen extends Query_BaseInstance {
		public Query_GetInstanzen(DataSource ds) {
			super(ds, sql_getInstanzen);
			compile();
		}
	}
	
	private class Query_GetInstanzFromUser extends Query_BaseInstance {
		public Query_GetInstanzFromUser(DataSource ds) {
			super(ds, sql_getInstanzFromUser);
			super.declareParameter(new SqlParameter("UNr", Types.INTEGER));
			compile();
		}
	}
	
	private class Query_GetInstanzFromActivity extends Query_BaseInstance {
		public Query_GetInstanzFromActivity(DataSource ds) {
			super(ds, sql_getInstanzFromActivity);
			super.declareParameter(new SqlParameter("WNr", Types.INTEGER));
			super.declareParameter(new SqlParameter("ANr", Types.INTEGER));
			compile();
		}
	}
	
	private class Query_GetInstanzById extends Query_BaseInstance {
		public Query_GetInstanzById(DataSource ds) {
			super(ds, sql_getInstanzById);
			super.declareParameter(new SqlParameter("INr", Types.INTEGER));
		}
	}
	
	private class Query_InsertInstanz extends SqlUpdate {
		public Query_InsertInstanz(DataSource ds) {
			setDataSource(ds);
			setSql(sql_insertInstanz);
			declareParameter(new SqlParameter(Types.INTEGER)); //WNr
			declareParameter(new SqlParameter(Types.INTEGER)); //ANr
			declareParameter(new SqlParameter(Types.INTEGER)); //UNr
			declareParameter(new SqlParameter(Types.DATE));    //Datum
			declareParameter(new SqlParameter(Types.BOOLEAN)); //Accepted
			declareParameter(new SqlParameter(Types.VARCHAR)); //Description
			declareParameter(new SqlParameter(Types.VARCHAR)); //Name
			
		}
	}
	
	private class Query_DeleteInstanz extends SqlUpdate {
		public Query_DeleteInstanz(DataSource ds) {
			setDataSource(ds);
			setSql(sql_deleteInstanz);
			declareParameter(new SqlParameter("INr", Types.INTEGER)); 
		}		
	}
	
	private class Query_UpdateInstanz extends SqlUpdate {
		public Query_UpdateInstanz(DataSource ds) {
			setDataSource(ds);
			setSql(sql_updateInstanz);
			declareParameter(new SqlParameter("WNr",   Types.INTEGER)); 
			declareParameter(new SqlParameter("ANr",   Types.INTEGER)); 
			declareParameter(new SqlParameter("UNr",   Types.INTEGER)); 
			declareParameter(new SqlParameter("Datum", Types.DATE)); 
			declareParameter(new SqlParameter("Accepted", Types.BOOLEAN));
			declareParameter(new SqlParameter("Description", Types.VARCHAR));
			declareParameter(new SqlParameter("Name", Types.VARCHAR));
			declareParameter(new SqlParameter("INr",   Types.INTEGER));    
		}		
	}
	
	private class Query_getInsertID extends MappingSqlQuery{
		/**
		 * This class provides the ID of the last inserted Object
		 * 
		 * @param ds
		 * 			A DataSource
		 */
		public Query_getInsertID(DataSource ds){
			super(ds,sql_getInsertID);
			compile();
		}
		
		protected Object mapRow(ResultSet rs, int rowNumber)
				throws SQLException {
			Integer id = new Integer(rs.getInt("@p0"));
			return id;
		}
	}
	
	public void init() {
		query_getallusers = new Query_GetAllUsers(dataSource);
		query_getuserpernr = new Query_GetUserperNr(dataSource);
		query_insertuser = new Query_InsertUser(dataSource);
		query_updateuser = new Query_updateUser(dataSource);
		query_deleteuser = new Query_DeleteUser(dataSource);
		
		query_getallgroups = new Query_GetAllGroups(dataSource);
		query_getgruppepernr = new Query_GetGruppeperNr(dataSource);
		query_insertgruppe = new Query_InsertGruppe(dataSource);
		query_updategruppe = new Query_UpdateGruppe(dataSource);
		query_deletegruppe = new Query_DeleteGruppe(dataSource);
		
		query_getusergroup = new Query_GetUsergroup(dataSource);
		query_getgroupofuser = new Query_GetGroupsofUser(dataSource);
		query_insertusergroup = new Query_InsertUsergroup(dataSource);
		query_deleteusergroup = new Query_DeleteUsergroup(dataSource);
		
		query_insertworkflow = new Query_InsertWorkflow(dataSource);
		query_getallworkflows = new Query_GetAllWorkflows(dataSource);	
		query_getworkflow = new Query_GetWorkflow(dataSource);
		query_deleteworkflow = new Query_DeleteWorkflow(dataSource);
		query_updateworkflow = new Query_UpdateWorkflow(dataSource);	

		query_getactivity = new Query_GetActivity(dataSource);
		query_getallactivities = new Query_GetAllActivities(dataSource);
		query_deleteactivity = new Query_DeleteActivity(dataSource);
		query_updateactivity = new Query_UpdateActivity(dataSource);
		query_insertactivity = new Query_InsertActivity(dataSource);
		
		query_insertantwort = new Query_InsertAntwort(dataSource);
		query_deleteantwort = new Query_DeleteAntwort(dataSource);
		query_getantwort =  new Query_GetAntwort(dataSource);	
		query_getantwortenfromactivity = new Query_GetAntwortenfromActivity(dataSource); 	
		query_updateantwort = new Query_UpdateAntwort(dataSource);
		
		query_getdokument = new Query_GetDokument(dataSource);	
		query_insertdokument = new Query_InsertDokument(dataSource);
		query_deletedokument = new Query_DeleteDokument(dataSource);
		query_deletedokumente = new Query_DeleteDokumente(dataSource);
		query_updatedokument = new Query_UpdateDokument(dataSource);
		
		query_insertinstanz = new Query_InsertInstanz(dataSource);
		query_getinstanzen = new Query_GetInstanzen(dataSource);
		query_getinstanzbyid = new Query_GetInstanzById(dataSource);
		query_getinstanzfromworkflow = new Query_GetInstanzFromWorkflow(dataSource);	
		query_getinstanzfromuser = new Query_GetInstanzFromUser(dataSource);
		query_getinstanzfromactivity = new Query_GetInstanzFromActivity(dataSource);
		query_deleteinstanz = new Query_DeleteInstanz(dataSource);
		query_updateinstanz = new Query_UpdateInstanz(dataSource);
		
		query_getInsertID = new Query_getInsertID(dataSource);
	}
	
	public void destroy() {
	}
	
	/****User/Group DAO****/
	
	public List<User> getUsers() {
		return query_getallusers.execute();
	}
	
	public User getUserById(int id) {
		List l = query_getuserpernr.execute(id);
		
		if(l.size() == 1) {
			User u = (User)l.get(0);
			return u;
		}
		else
			return null;
	}
	
	public List<Group> getGroups() {
		return query_getallgroups.execute();
	}
	
	public Group getGroupById(int id) {
		List l = query_getgruppepernr.execute(id);
		
		if(l.size() == 1) {
			Group g = (Group)l.get(0);
			return g;
		}
		else
			return null;
	}
	
	public List<Group> getUsersGroups(User u) {
		return query_getgroupofuser.execute(u.getId());
	}
	
	public List<User> getUsersOfGroup(Group g) {
		return query_getusergroup.execute(g.getId());
	}
	
	public int createUser(User u) {
		final Object[] param = new Object[] { u.getUsername(), u.getFirstname(), u.getSurname(),
				                        u.getPhone(), u.getEmail(), u.getPasswdhash(), u.getType()};
		
		TransactionTemplate tt = new TransactionTemplate(transactionManager);
		Object result = tt.execute(new TransactionCallback() {
			public Object doInTransaction(TransactionStatus status) {
				query_insertuser.update(param);
				List results = query_getInsertID.execute();
				Integer id = (Integer)results.get(0);
				return id;
			}
		});
		Integer id = (Integer) result;
		u.setId(id.intValue());
		return id.intValue();
	}
	
	public int createGroup(Group g) {
		final Object[] param = new Object[] { g.getName(), g.getDescription() };
		
		TransactionTemplate tt = new TransactionTemplate(transactionManager);
		Object result = tt.execute(new TransactionCallback() {
			public Object doInTransaction(TransactionStatus status) {
				query_insertgruppe.update(param);
				List results = query_getInsertID.execute();
				Integer id = (Integer)results.get(0);
				return id;
			}
		});
		Integer id = (Integer) result;
		g.setId(id.intValue());
		return id.intValue();
	}
	
	public void addUserToGroup(Group g, User u) {
		final Object[] param = new Object[] { u.getId(), g.getId() };
		query_insertusergroup.update(param);
	}
	
	public void deleteUserGroup(Group g, User u) {
		final Object[] param = new Object[] { u.getId(), g.getId() };
		query_deleteusergroup.update(param);
	}
	
	public void updateUser(User u) {
		final Object[] param = new Object[] { u.getUsername(), u.getFirstname(), u.getSurname(),
				                              u.getPhone(), u.getEmail(), u.getPasswdhash(), u.getType(), u.getId()};
		query_updateuser.update(param);
	}
	
	public void updateGroup(Group g) {
		final Object[] param = new Object[] { g.getName(), g.getDescription(), g.getId() };
		query_updategruppe.update(param);
	}
	
	public void deleteGroup(Group g) {
		final Object[] param = new Object[] { g.getId() };
		query_deletegruppe.update(param);
	}
	
	public void deleteUser(User u) {
		final Object[] param = new Object[] { u.getId() };
		query_deleteuser.update(param);
	}

	/*****Workflow DAO*****/
	
	public int createInstance(Run i) {
		final Object[] param = new Object[] { i.getWf().getWNr(),
				                              i.getNode().getId(), i.getUser().getId(),
				                              i.getDate(), i.isAccepted(), i.getDesc(), i.getName() };
		
		TransactionTemplate tt = new TransactionTemplate(transactionManager);
		Object result = tt.execute(new TransactionCallback() {
			public Object doInTransaction(TransactionStatus status) {
				query_insertinstanz.update(param);
				List results = query_getInsertID.execute();
				Integer id = (Integer)results.get(0);
				return id;
			}
		});
		Integer id = (Integer) result;
		i.setId(id.intValue());
		return id.intValue();
	}
	
	public void deleteInstance(Run i) {
		final Object[] param = new Object[] { i.getId() };
		query_deleteinstanz.update(param);
	}

	public int createWorkflow(Workflow w) {
		final Object[] param = new Object[] { w.getName(), w.getDate(), w.getDesc(),
				                              w.getStartnode().getId() };
		
		TransactionTemplate tt = new TransactionTemplate(transactionManager);
		Object result = tt.execute(new TransactionCallback() {
			public Object doInTransaction(TransactionStatus status) {
				query_insertworkflow.update(param);
				List results = query_getInsertID.execute();
				Integer id = (Integer)results.get(0);
				return id;
			}
		});
		Integer id = (Integer) result;
		w.setWNr(id);
		//Create Nodes/Conditions/Edges
		Set<Node> s = w.getNodes();
		for(Node n : s) {
			createNode(n);
			//System.out.println("Node created: " + n.getId());
		}
		insertNodes(w.getStartnode());
		//Startnode updaten (DB)
		this.updateWorkflow(w);

		return id.intValue();
	}
	
	public void updateWorkflow(Workflow w) {
		final Object[] param = new Object[] { w.getName(), w.getDate(), w.getDesc(),
                w.getStartnode().getId(), w.getWNr() };
		query_updateworkflow.update(param);
		
		updateNodes(w.getStartnode());
	}

	public void deleteWorkflow(Workflow w) {
		
		Set<Node> nl = w.getNodes();
		ArrayList<Integer> edges = new ArrayList<Integer>();
		
		for(Node n : nl) {
			List<Edge> el = n.getConditions().getEdges();
			for(Edge e : el) {
				if(!edges.contains(Integer.valueOf(e.getId())))
					edges.add(Integer.valueOf(e.getId()));
			}
		}
		
		for(Integer i : edges) {
			final Object[] param = new Object[] { i.intValue() };
			query_deleteantwort.update(param);
		}
		
		for(Node n : nl) {
			deleteNode(n);
		}
		
		final Object[] param = new Object[] { w.getWNr() };
		query_deleteworkflow.update(param);
	}
	
	public int createDocument(Document d) {
		final Object[] param = new Object[] { d.getName(), d.getVersion(), d.getBinary(),
				                              d.getR().getId() };
		log.debug("rid" + d.getR().getId());
		TransactionTemplate tt = new TransactionTemplate(transactionManager);
		Object result = tt.execute(new TransactionCallback() {
			public Object doInTransaction(TransactionStatus status) {
				query_insertdokument.update(param);
				List results = query_getInsertID.execute();
				Integer id = (Integer)results.get(0);
				return id;
			}
		});
		Integer id = (Integer) result;
		d.setId(id.intValue());
		return id.intValue();
	}
	
	public void deleteDocument(Document d) {
		final Object[] param = new Object[] { d.getId() };
		query_deletedokument.update(param);
	}
	
	public void deleteDocumentsfromInstance(int inr) {
		final Object[] param = new Object[] { inr };
		query_deletedokumente.update(param);
	}

	public List<Workflow> getAllWorkflows() {
		List<Workflow> l = query_getallworkflows.execute();
		
		for(Workflow w : l) {
			getNodes(w);
		}
		return l;
	}

	public List<Document> getDocuments(int runId) {
		return query_getdokument.execute(runId);
	}
	
	public List<Document> getDocumentWithoutData(int runId) {
		return query_getdokumentohne.execute(runId);
	}

	public List<Run> getInstances() {
		return query_getinstanzen.execute();
	}
	
	public Workflow getWorkflow(int wnr) {
		List l = query_getworkflow.execute(wnr);
		
		if(l.size() == 1) {
			Workflow w = (Workflow)l.get(0);
			getNodes(w);
			return w;
		}
		else
			return null;
	}

	public void updateInstance(Run i) {
		final Object[] param = new Object[] { i.getWf().getWNr(),
                i.getNode().getId(), i.getUser().getId(), i.getDate(), i.isAccepted(),i.getDesc(), i.getName(),i.getId()};
		
		query_updateinstanz.update(param);
	}

	public List<Run> getInstances(int wnr, int anr) {
		final Object[] param = new Object[] { wnr, anr };
		return query_getinstanzfromactivity.execute(param);
	}

	public List<Run> getInstances(int wnr) {
		return query_getinstanzfromworkflow.execute(wnr);
	}
	
	public Run getInstanceById(int inr) {
		final Object[] param = new Object[] { inr };
		return (Run)query_getinstanzbyid.execute(param).get(0);
	}
	
	/***************** Private Methods *********************/
	
	private int createEdge(Edge e) {
		final Object[] param = new Object[] { e.getFromNode().getId(), 
				                              e.getToNode().getId(), e.getDescription() };

		TransactionTemplate tt = new TransactionTemplate(transactionManager);
		Object result = tt.execute(new TransactionCallback() {
			public Object doInTransaction(TransactionStatus status) {
				log.debug(param[0] + "-" + param[1] + "-" + param[2]);
				query_insertantwort.update(param);
				List results = query_getInsertID.execute();
				Integer id = (Integer)results.get(0);
				return id;
			}
		});
		Integer id = (Integer) result;
		e.setId(id.intValue());
		return id.intValue();
	}

	private void deleteEdge(Edge e) {
		final Object[] param = new Object[] { e.getId() };
		query_deleteantwort.update(param);
	}

	private void deleteNode(Node n) {
		final Object[] param = new Object[] { n.getW().getWNr(), n.getId() };
		query_deleteactivity.update(param);
	}
	
	private int createNode(Node n) {
		final Object[] param = new Object[] { n.getW().getWNr(), n.getGroup().getId(), n.getName(),
											  n.getConditions().getTitel(), n.getX(), n.getY() };
		
		TransactionTemplate tt = new TransactionTemplate(transactionManager);
		Object result = tt.execute(new TransactionCallback() {
			public Object doInTransaction(TransactionStatus status) {
				query_insertactivity.update(param);
				List results = query_getInsertID.execute();
				Integer id = (Integer)results.get(0);
				return id;
			}
		});
		Integer id = (Integer) result;
		n.setId(id.intValue());
		return id.intValue();
	}

	private List<Edge> getEdges(int anr) {
		List l = query_getantwortenfromactivity.execute(anr);
		
		return l;
	}
	
	private List<Node> getAllNodes(int wnr) {
		return query_getallactivities.execute(wnr);
	}

	private Node getNode(int wnr, int anr) {
		final Object[] param = new Object[] { wnr, anr };
		List l = query_getactivity.execute(param);
		
		if(l.size() == 1) {
			Node n = (Node)l.get(0);
			return n;
		}
		else
			return null;
	}
    
	private void updateEdge(Edge e) {
		final Object[] param = new Object[] { e.getFromNode().getId(), 
                e.getToNode().getId(), e.getDescription(), e.getId() };
		
		query_updateantwort.update(param);
	}

	private void updateNode(Node n) {
		final Object[] param = new Object[] { n.getGroup().getId(), n.getName(),
				  n.getDescription(), n.getX(), n.getY(),
				  n.getW().getWNr(), n.getId() };
		query_updateactivity.update(param);
	}
	
	private Set<Node> insertNodes(Node startnode) {
		Set<Node> startSet = new HashSet<Node>();
		startSet.add(startnode);
		return insertNodesRecoursive(startnode, startSet);
	}
	
	private Set<Node> insertNodesRecoursive(Node start, Set<Node> nodes) {
		//System.out.println("Startnode: " + start.getName() + "; conditions: " + start.getConditions().getEdges().size());
		Conditions c = start.getConditions();
		//createNode(start);
		for(Edge g : c.getEdges()) {
			Node to = g.getToNode();
			if(!nodes.contains(to)) {
				//System.out.println("adding: " + to.getName());
				nodes.add(to);
				nodes.addAll(insertNodesRecoursive(to, nodes));
				//return nodes;
			}
			log.debug("inserting edge: " + g.getFromNode().getName() + "-" +
                    g.getToNode().getName() + "----" + g.getId());
			createEdge(g);
		}
		return nodes;
	}
	
	private Set<Node> updateNodes(Node startnode) {
		Set<Node> startSet = new HashSet<Node>();
		startSet.add(startnode);
		return updateNodesRecoursive(startnode, startSet);
	}
	
	private Set<Node> updateNodesRecoursive(Node start, Set<Node> nodes) {
		log.debug("Startnode: " + start.getName() + "; conditions: " + start.getConditions().getEdges().size());
		Conditions c = start.getConditions();
		updateNode(start);
		for(Edge g : c.getEdges()) {
			Node to = g.getToNode();
			if(!nodes.contains(to)) {
				log.debug("adding: " + to.getName());
				nodes.add(to);
				nodes.addAll(updateNodesRecoursive(to, nodes));
			}
			updateEdge(g);
		}
		return nodes;
	}
	
	private void getNodes(Workflow w) {
		List<Node> ln = this.getAllNodes(w.getWNr());
		
		for(Node n : ln) {
			Conditions c = new Conditions(n, n.getDescription());
			n.setConditions(c);
			n.setW(w);
			log.debug("GN: adding node: " + n.getName());
			
			if(n.getId() == w.getStartnode().getId())
				w.setStartnode(n);
			List<Edge> le = getEdges(n.getId());
			for(Edge e : le) {
				log.debug("GN: adding edge: " + e.getDescription() + "-" + e.getFromNode().getId() + "-" + e.getToNode().getId());
				c.addEdge(e);
				e.setFromNode(getrightNode(ln, e.getFromNode().getId()));
				e.setToNode(getrightNode(ln, e.getToNode().getId()));
			}
		}
	}
	
	private Node getrightNode(List<Node> l, int id) {
		for(Node n : l) {
			if(n.getId() == id)
				return n;
		}
		return null;
	}

	/****************** Getter/Setter ********************* */
	
	public void setDataSource(DataSource dataSource){
		this.dataSource = dataSource;
	}
	
	public void setTransactionManager(
			PlatformTransactionManager transactionManager) {
		this.transactionManager = transactionManager;
	}

	public String getSql_getInsertID() {
		return sql_getInsertID;
	}

	public void setSql_getInsertID(String sql_getInsertID) {
		this.sql_getInsertID = sql_getInsertID;
	}

	public String getSql_getAllUsers() {
		return sql_getAllUsers;
	}

	public void setSql_getAllUsers(String sql_getAllUsers) {
		this.sql_getAllUsers = sql_getAllUsers;
	}

	public String getSql_getUserperNr() {
		return sql_getUserperNr;
	}

	public void setSql_getUserperNr(String sql_getUserperNr) {
		this.sql_getUserperNr = sql_getUserperNr;
	}

	public String getSql_insertUser() {
		return sql_insertUser;
	}

	public void setSql_insertUser(String sql_insertUser) {
		this.sql_insertUser = sql_insertUser;
	}

	public String getSql_updateUser() {
		return sql_updateUser;
	}

	public void setSql_updateUser(String sql_updateUser) {
		this.sql_updateUser = sql_updateUser;
	}

	public String getSql_deleteUser() {
		return sql_deleteUser;
	}

	public void setSql_deleteUser(String sql_deleteUser) {
		this.sql_deleteUser = sql_deleteUser;
	}

	public String getSql_getAllGroups() {
		return sql_getAllGroups;
	}

	public void setSql_getAllGroups(String sql_getAllGroups) {
		this.sql_getAllGroups = sql_getAllGroups;
	}

	public String getSql_getGruppeperNr() {
		return sql_getGruppeperNr;
	}

	public void setSql_getGruppeperNr(String sql_getGruppeperNr) {
		this.sql_getGruppeperNr = sql_getGruppeperNr;
	}

	public String getSql_insertGruppe() {
		return sql_insertGruppe;
	}

	public void setSql_insertGruppe(String sql_insertGruppe) {
		this.sql_insertGruppe = sql_insertGruppe;
	}

	public String getSql_updateGruppe() {
		return sql_updateGruppe;
	}

	public void setSql_updateGruppe(String sql_updateGruppe) {
		this.sql_updateGruppe = sql_updateGruppe;
	}

	public String getSql_deleteGruppe() {
		return sql_deleteGruppe;
	}

	public void setSql_deleteGruppe(String sql_deleteGruppe) {
		this.sql_deleteGruppe = sql_deleteGruppe;
	}

	public String getSql_getUsergroup() {
		return sql_getUsergroup;
	}

	public void setSql_getUsergroup(String sql_getUsergroup) {
		this.sql_getUsergroup = sql_getUsergroup;
	}

	public String getSql_getGroupsofUser() {
		return sql_getGroupsofUser;
	}

	public void setSql_getGroupsofUser(String sql_getGroupsofUser) {
		this.sql_getGroupsofUser = sql_getGroupsofUser;
	}

	public String getSql_insertUsergroup() {
		return sql_insertUsergroup;
	}

	public void setSql_insertUsergroup(String sql_insertUsergroup) {
		this.sql_insertUsergroup = sql_insertUsergroup;
	}

	public String getSql_deleteUsergroup() {
		return sql_deleteUsergroup;
	}

	public void setSql_deleteUsergroup(String sql_deleteUsergroup) {
		this.sql_deleteUsergroup = sql_deleteUsergroup;
	}

	public String getSql_getAllWorkflows() {
		return sql_getAllWorkflows;
	}

	public void setSql_getAllWorkflows(String sql_getAllWorkflows) {
		this.sql_getAllWorkflows = sql_getAllWorkflows;
	}

	public String getSql_getWorkflow() {
		return sql_getWorkflow;
	}

	public void setSql_getWorkflow(String sql_getWorkflow) {
		this.sql_getWorkflow = sql_getWorkflow;
	}

	public String getSql_insertWorkflow() {
		return sql_insertWorkflow;
	}

	public void setSql_insertWorkflow(String sql_insertWorkflow) {
		this.sql_insertWorkflow = sql_insertWorkflow;
	}

	public String getSql_deleteWorkflow() {
		return sql_deleteWorkflow;
	}

	public void setSql_deleteWorkflow(String sql_deleteWorkflow) {
		this.sql_deleteWorkflow = sql_deleteWorkflow;
	}

	public String getSql_getAllActivities() {
		return sql_getAllActivities;
	}

	public void setSql_getAllActivities(String sql_getAllActivities) {
		this.sql_getAllActivities = sql_getAllActivities;
	}

	public String getSql_getActivity() {
		return sql_getActivity;
	}

	public void setSql_getActivity(String sql_getActivity) {
		this.sql_getActivity = sql_getActivity;
	}

	public String getSql_insertActivity() {
		return sql_insertActivity;
	}

	public void setSql_insertActivity(String sql_insertActivity) {
		this.sql_insertActivity = sql_insertActivity;
	}

	public String getSql_updateActivity() {
		return sql_updateActivity;
	}

	public void setSql_updateActivity(String sql_updateActivity) {
		this.sql_updateActivity = sql_updateActivity;
	}

	public String getSql_deleteActivity() {
		return sql_deleteActivity;
	}

	public void setSql_deleteActivity(String sql_deleteActivity) {
		this.sql_deleteActivity = sql_deleteActivity;
	}

	public String getSql_getAntwort() {
		return sql_getAntwort;
	}

	public void setSql_getAntwort(String sql_getAntwort) {
		this.sql_getAntwort = sql_getAntwort;
	}

	public String getSql_getAntwortenfromActivity() {
		return sql_getAntwortenfromActivity;
	}

	public void setSql_getAntwortenfromActivity(String sql_getAntwortenfromActivity) {
		this.sql_getAntwortenfromActivity = sql_getAntwortenfromActivity;
	}

	public String getSql_insertAntwort() {
		return sql_insertAntwort;
	}

	public void setSql_insertAntwort(String sql_insertAntwort) {
		this.sql_insertAntwort = sql_insertAntwort;
	}

	public String getSql_updateAntwort() {
		return sql_updateAntwort;
	}

	public void setSql_updateAntwort(String sql_updateAntwort) {
		this.sql_updateAntwort = sql_updateAntwort;
	}

	public String getSql_deleteAntwort() {
		return sql_deleteAntwort;
	}

	public void setSql_deleteAntwort(String sql_deleteAntwort) {
		this.sql_deleteAntwort = sql_deleteAntwort;
	}

	public String getSql_getDokument() {
		return sql_getDokument;
	}

	public void setSql_getDokument(String sql_getDokument) {
		this.sql_getDokument = sql_getDokument;
	}

	public String getSql_insertDokument() {
		return sql_insertDokument;
	}

	public void setSql_insertDokument(String sql_insertDokument) {
		this.sql_insertDokument = sql_insertDokument;
	}

	public String getSql_updateDokument() {
		return sql_updateDokument;
	}

	public void setSql_updateDokument(String sql_updateDokument) {
		this.sql_updateDokument = sql_updateDokument;
	}

	public String getSql_deleteDokument() {
		return sql_deleteDokument;
	}

	public void setSql_deleteDokument(String sql_deleteDokument) {
		this.sql_deleteDokument = sql_deleteDokument;
	}

	public String getSql_getInstanzFromWorkflow() {
		return sql_getInstanzFromWorkflow;
	}

	public void setSql_getInstanzFromWorkflow(String sql_getInstanzFromWorkflow) {
		this.sql_getInstanzFromWorkflow = sql_getInstanzFromWorkflow;
	}

	public String getSql_getInstanzFromUser() {
		return sql_getInstanzFromUser;
	}

	public void setSql_getInstanzFromUser(String sql_getInstanzFromUser) {
		this.sql_getInstanzFromUser = sql_getInstanzFromUser;
	}

	public String getSql_insertInstanz() {
		return sql_insertInstanz;
	}

	public void setSql_insertInstanz(String sql_insertInstanz) {
		this.sql_insertInstanz = sql_insertInstanz;
	}

	public String getSql_deleteInstanz() {
		return sql_deleteInstanz;
	}

	public void setSql_deleteInstanz(String sql_deleteInstanz) {
		this.sql_deleteInstanz = sql_deleteInstanz;
	}
	
	public String getSql_updateWorkflow() {
		return sql_updateWorkflow;
	}
	
	public void setSql_updateWorkflow(String sql_updateWorkflow) {
		this.sql_updateWorkflow = sql_updateWorkflow;
	}

	public String getSql_getInstanzen() {
		return sql_getInstanzen;
	}

	public void setSql_getInstanzen(String sql_getInstanzen) {
		this.sql_getInstanzen = sql_getInstanzen;
	}

	public String getSql_getInstanz() {
		return sql_getInstanz;
	}

	public void setSql_getInstanz(String sql_getInstanz) {
		this.sql_getInstanz = sql_getInstanz;
	}

	public String getSql_getInstanzFromActivity() {
		return sql_getInstanzFromActivity;
	}

	public void setSql_getInstanzFromActivity(String sql_getInstanzFromActivity) {
		this.sql_getInstanzFromActivity = sql_getInstanzFromActivity;
	}

	public String getSql_updateInstanz() {
		return sql_updateInstanz;
	}

	public void setSql_updateInstanz(String sql_updateInstanz) {
		this.sql_updateInstanz = sql_updateInstanz;
	}

	public String getSql_getInstanzById() {
		return sql_getInstanzById;
	}

	public void setSql_getInstanzById(String sql_getInstanzById) {
		this.sql_getInstanzById = sql_getInstanzById;
	}

	public String getSql_deleteDokumente() {
		return sql_deleteDokumente;
	}

	public void setSql_deleteDokumente(String sql_deleteDokumente) {
		this.sql_deleteDokumente = sql_deleteDokumente;
	}

	public String getSql_getDokumentOhne() {
		return sql_getDokumentOhne;
	}

	public void setSql_getDokumentOhne(String sql_getDokumentOhne) {
		this.sql_getDokumentOhne = sql_getDokumentOhne;
	}
}
